import Vue from 'vue'
import Router from 'vue-router'
// import Home from '@/pages/home/Home'
// import City from '@/pages/city/City'
// import Detail from '@/pages/detail/Detail'

Vue.use(Router)

export default new Router({
  // 异步加载测试部分
  // 原来的代码，需要一个个导入组件
  //   routes: [
  //   {
  //     path: '/',
  //     name: 'Home',
  //     component: Home
  //   }, {
  //     path: '/city',
  //     name: 'City',
  //     component: City
  //   }, {
  //     path: '/detail/:id', // 动态路由
  //     name: 'Detail',
  //     component: Detail
  //   }
  // ],
  // 改后的代码，不需要在上面导入，直接在组件名称处导入
  routes: [
    {
      path: '/',
      name: 'Home',
      component: () => import('@/pages/home/Home')
    }, {
      path: '/city',
      name: 'City',
      component: () => import('@/pages/city/City')
    }, {
      path: '/detail/:id', // 动态路由
      name: 'Detail',
      component: () => import('@/pages/detail/Detail')
    }
  ],
  scrollBehavior (to, from, savedPosition) { // 让页面的初始位置在最顶端
    return { x: 0, y: 0 }
  }
})
